import { MatPaginatorIntl } from '@angular/material/paginator';

export class AngularMaterial {
    static getDutchRangeLabel(page: number, pageSize: number, length: number): string {
        if (length == 0 || pageSize == 0) {
            return `0`;
        }

        length = Math.max(length, 0);

        const startIndex = page * pageSize;

        const endIndex = startIndex < length ?
            Math.min(startIndex + pageSize, length) :
            startIndex + pageSize;

        return `当前为第${page + 1}页 ，共${Math.ceil(length / pageSize)}页，第${startIndex + 1} - ${endIndex} 条，共 ${length}条`;
    }

    static getDutchPaginatorIntl(): MatPaginatorIntl {
        const p = new MatPaginatorIntl();

        p.itemsPerPageLabel = '每页显示条数：';
        p.nextPageLabel = '下一页';
        p.previousPageLabel = '上一页';
        p.firstPageLabel = '第一页';
        p.lastPageLabel = '最后一页';
        p.getRangeLabel = AngularMaterial.getDutchRangeLabel;

        return p;
    }
}